package org.example.controller;

import org.example.model.Form;
import org.example.service.formService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/form")
@CrossOrigin
public class formController {
    @Autowired
    private formService formService;
    @PostMapping("/save")
    public  long save(@RequestBody Form form){
         if(formService.findFormService(form.getFormName())==null) {
             formService.saveFormService(form);
             return 1;
         }else
             return 0;
    }
    @PostMapping("/select")
    public  Form select(@RequestBody Map<String, Object> requestDate){
        String formName=requestDate.get("formName").toString();
        return formService.findFormService(formName);
    }
    @PostMapping("/update")
    public  long update(@RequestBody Form form){
        if(form.getRules()==null) {
            return 0;
        }
        return formService.updateFormService(form);
    }
    @PostMapping("/delete")
    public  long deleteForm(@RequestBody Map<String, Object> requestDate){
        String formName=requestDate.get("formName").toString();
        if(formService.findFormService(formName)==null) {
            return 0;
        }
        formService.deleteFormService(formName);
        return 1;
    }
    @GetMapping("/save1")
    public  String save1(){
        System.out.println("awdawd");
        return  "ohhhh";
    }

}
